import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../views/layout/index.vue'
import Login from '../views/login/Login.vue'
import Home from '@/views/home/Home.vue'

//产品
const Product = () => import('../views/product/index.vue')
const List = () => import('../views/product/list/list.vue')
const Category = () => import('../views/product/category/category.vue')
const AddProduct = ()=>import('../views/product/addProduct/addProduct.vue')
//订单
const Order = () => import('../views/order/index.vue')
const OrderList = () => import('../views/order/list/list.vue')
const Collect = () => import('../views/order/collect/collect.vue')

const routes = [
  {
    path: '/',
    name: 'layout',
    component:Layout,
    children: [
      {
        path: '/',
        name: 'home',
        component: Home,
        meta: {
          title: '首页'
        },
      },
      {
        path: '/product',//产品管理
        name: 'product',
        component: Product,
        children: [
            {
                path: 'list',//访问/product/list
                name: 'list',
                component: List,
            },
            {
                path: 'category',//访问/product/category
                name: 'category',
                component: Category,
            },
            {
              path: 'addProduct',//访问/product/addProduct
              name: 'addProduct',
              component:AddProduct,
              meta:{activeMenu:'/product/addProduct'}
          }
        ],
    },
    {
      path: '/order',//订单
      name: 'order',
      component: Order,
      redirect: '/order/order-list',
      meta: {
          title: '订单管理'
      },
      children: [
          {
              path: 'order-list',//访问/order/order-list
              name: 'order-list',
              component: OrderList,
              meta: {
                  title: '订单列表'
              },
          },
          {
              path: 'collect',//访问/order/collect
              name: 'collect',
              component: Collect,
              meta: {
                  title: '汇总清单'
              },
          },
      ],
  },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login 
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
